﻿using System;
using System.Linq;
using Microsoft.Win32.TaskScheduler;

namespace TSMonitor.Core
{
	public class TaskInfo
	{
		public string Name { get; set; }

		public TaskState State { get; set; }

		public DateTime LastRunTime { get; set; }

		public int LastTaskResult { get; set; }

		public bool Enabled { get; set; }

		public ServerInfo ServerInfo { get; set; }

		public string Path { get; set; }

		public override int GetHashCode()
		{
			unchecked
			{
				var items = new object[]
		                        {
		                            Name, State, LastRunTime, LastTaskResult, Enabled, ServerInfo.TargetServer
		                        };
				return items.Select(x => x.ToString()).Aggregate((res, next) => res + next).GetHashCode();
			}
		}

		public override bool Equals(object obj)
		{
			if(obj != null && obj is TaskInfo)
			{
				return GetHashCode() == obj.GetHashCode();
			}
			return false;
		}
	}
}